package com.ehotting.edsta.csharpServer.controller;

import com.alibaba.fastjson.JSON;
import com.ehotting.eaf.core.domain.R;
import com.ehotting.eaf.core.utils.poi.ExcelUtil;
import com.ehotting.eaf.core.web.controller.BaseController;
import com.ehotting.eaf.core.web.page.TableDataInfo;
import com.ehotting.edsta.common.log.annotation.Log;
import com.ehotting.edsta.common.log.enums.BusinessType;
import com.ehotting.edsta.csharpServer.domain.ProjectSimulation;
import com.ehotting.edsta.csharpServer.domain.ProjectSimulationType;
import com.ehotting.edsta.csharpServer.domain.vo.ProjectSimulationVo;
import com.ehotting.edsta.csharpServer.service.IProjectSimulationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 工程仿真计算Controller
 * 
 * @author edsta
 * @date 2023-04-11
 */
@RestController
@RequestMapping("/simulation")
@Api(tags = "ProjectSimulationController",description = "工程仿真步骤相关接口")
public class ProjectSimulationController extends BaseController
{
    @Autowired
    private IProjectSimulationService projectSimulationService;

    /**
     * 查询工程仿真计算列表
     */
    @ApiOperation("查询工程仿真计算列表")
    @GetMapping("/list")
    public TableDataInfo list(ProjectSimulation projectSimulation)
    {
        startPage();
        List<ProjectSimulation> list = projectSimulationService.selectProjectSimulationList(projectSimulation);
        return getDataTable(list);
    }

    /**
     * 查询工程仿真计算列表
     * @return
     */
    @Log(title = "工程仿真计算",businessType = BusinessType.GET_DATA)
    @ApiOperation("查询工程仿真计算列表（无分页）")
    @GetMapping("/listAll")
    public R<List<ProjectSimulation>> listAll(ProjectSimulation projectSimulation)
    {
        List<ProjectSimulation> list = projectSimulationService.selectProjectSimulationList(projectSimulation);
        return R.ok(list);
    }

    /**
     * 查询最新工程仿真计算
     * @return
     */
    @Log(title = "工程仿真计算",businessType = BusinessType.GET_DATA)
    @ApiOperation("查询最新工程仿真计算")
    @GetMapping("/getLatest")
    public R<ProjectSimulation> getLatest(ProjectSimulationVo projectSimulation)
    {
        ProjectSimulation result = null;
        if (ProjectSimulationType.ARGS.toString().equals(projectSimulation.getDataType())){
            result = projectSimulationService.selectProjectSimulationArgs(projectSimulation);
        }
        if (ProjectSimulationType.RES.toString().equals(projectSimulation.getDataType())){
            result = projectSimulationService.selectProjectSimulationRes(projectSimulation);
        }
        return R.ok(result);
    }

    /**
     * 导出工程仿真计算列表
     */
    @Log(title = "工程仿真计算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectSimulation projectSimulation) throws IOException
    {
        List<ProjectSimulation> list = projectSimulationService.selectProjectSimulationList(projectSimulation);
        ExcelUtil<ProjectSimulation> util = new ExcelUtil<ProjectSimulation>(ProjectSimulation.class);
        util.exportExcel(response, list, "工程仿真计算数据");
    }

    /**
     * 获取工程仿真计算详细信息
     * @return
     */
    @ApiOperation("根据id获取工程仿真计算详细信息")
    @GetMapping(value = "/{id}")
    public R<ProjectSimulation> getInfo(@PathVariable("id") Long id)
    {
        return R.ok(projectSimulationService.selectProjectSimulationById(id));
    }

    /**
     * 新增工程仿真计算
     * @return
     */
    @Log(title = "工程仿真计算", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增工程仿真计算")
    public R<Integer> add(@RequestBody ProjectSimulation projectSimulation)
    {
        return R.ok(projectSimulationService.insertProjectSimulation(projectSimulation));
    }

    /**
     * 修改工程仿真计算
     * @return
     */
    @Log(title = "工程仿真计算", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public R<Integer> edit(@RequestBody ProjectSimulation projectSimulation)
    {
        return R.ok(projectSimulationService.updateProjectSimulation(projectSimulation));
    }

    /**
     * 删除工程仿真计算
     * @return
     */
    @ApiOperation("删除工程仿真计算")
    @Log(title = "工程仿真计算", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R<Integer> remove(@PathVariable Long[] ids)
    {
        return R.ok(projectSimulationService.deleteProjectSimulationByIds(ids));
    }
}
